package com.tang.algorithm.doublePointer;

/**
 * @author tlm
 * @Description 寻找重复数
 * @date 2020/7/21 1:36 下午
 */
public class LeetCode287 {
	public int findDuplicate(int[] nums) {
		int fast = 0, slow = 0;
		while (true) {
			fast = nums[nums[fast]];
			slow = nums[slow];
			if (fast == slow)
				break;
		}
		fast = 0;
		while (fast != slow) {
			fast = nums[fast];
			slow = nums[slow];
		}
		return fast;
	}
}
